package ${servicePack};



import com.neuedu.his.common.Page;
import com.neuedu.his.common.utils.ParamUtils;
import ${daoPackage}.${className}Dao;
import ${entityPackage}.${className};
import com.neuedu.his.common.core.BaseService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;



public class ${className}Service implements BaseService<${className}>   {

private ${className}Dao dao = new ${className}Dao();


public Page queryList(HttpServletRequest request){
int pageNo = 1;
int size = 10;

String paramPageNo = request.getParameter("pageNo");
String paraSize = request.getParameter("size");

if(!Objects.isNull(paramPageNo)){
pageNo = Integer.parseInt(paramPageNo);
}
if(!Objects.isNull(paraSize)){
size = Integer.parseInt(paraSize);
}

List paraList = new ArrayList();
String where  = "where 1=1   ";

<#--        String dname = request.getParameter("dname");-->
<#--        if(!Objects.isNull(dname)){-->
<#--            where += " and dname like concat('%',?,'%')";-->
<#--            paraList.add(dname);-->
<#--        }-->
Object[] params = paraList.toArray();
long total  = dao.selectCount(where,params);
List<${className}> data = dao.selectPage(where,pageNo,size,params);

return  Page.getInstatnce(pageNo ,size , data , total);
}


public boolean save(HttpServletRequest req) {

${className}  ${className?uncap_first}   =  ParamUtils.getParam(${className}.class,req);
return  dao.insert(${className?uncap_first}) >0;
}

public boolean update(HttpServletRequest req) {
${className}  ${className?uncap_first}   =  ParamUtils.getParam(${className}.class,req);
return  dao.updateById( ${className?uncap_first} ) >0;
}


public  ${className} queryById(HttpServletRequest req) {
String ${pkProp.name} = req.getParameter("${pkProp.name}");
String where = " where ${pkProp.columnName} = ?";
Object params[] = {${pkProp.name}};
return dao.selectOne(where,params);
}


/**
* 根据主键删除
* @param req
* @return
*/
public boolean deleteById(HttpServletRequest req) {
String ${pkProp.name} = req.getParameter("${pkProp.name}");
return dao.deleteById(Integer.parseInt(${pkProp.name}))>0;
}
}
